<?php

    namespace yaliSDK\message;

    class ExceptionFactory {
        static public $instance;
        private $localString;


        public function __construct($localString = []) {
            $this->localString = $localString;
            $this->localString = [
                0 => '操作失败',
                1 => '操作成功',
                Code::$ERROR => '操作失败',
                Code::$SUCCESS => '操作成功',
                Code::$VALIDATE_PASS => '验证成功',// 验证成功

                //##购票
                Code::$TICKET_ACTIVITY_START => '活动开始',
                Code::$TICKET_ACTIVITY_NOT_START => '活动未开始',
                Code::$TICKET_ACTIVITY_END => '抢票活动结束',
                Code::$EXCHANGE_TICKET_START => '兑换开始',
                Code::$EXCHANGE_TICKET_NOT_START => '兑换未开始',
                Code::$EXCHANGE_TICKET_END => '兑换结束',
                Code::$ALL_TICKET_IS_INITIAL => '已初始路线票',

                Code::$TICKET_BIND_SUCCESS => '绑定成功',
                Code::$EORROR_STICKET_NO_STOCK => '该线路已经满员了，试试其他线路吧!',
                Code::$EORROR_STICKET_BUY_QUANTIY_NO_ZERO => '购票不能为0',
                Code::$EORROR_STICKET_BUY_QUANTIY_MAX => '您的报名数量已达上限了，是否到订单中心查看?',
                Code::$TICKET_TYPE_ERROR => '报名码类型错误',

                Code::$ALL_TICKET_NOT_INITIAL => '没初始路线票',
                Code::$CUSTOMER_TICKET_MAX => '您的报名数量已达上限了，是否到订单中心查看?',
                // ##订单
                Code::$ERROR_SAVE_ORDER => '下单失败',
                Code::$SUCCESS_SAVE_ORDER => '下单成功',
                Code::$ERROR_EXISTED_ORDER => '顾客已创建过订单，不可重复创建',
                Code::$ORDER_PAY_ERROR => '支付失败',
                // ###订单状态
                Code::$ORDER_STATUS_WAIT_PAY => '待支付',
                Code::$ORDER_STATUS_PAYED => '已支付',
                Code::$ORDER_STATUS_CANCEL => '已取消',
                Code::$INVALIDE_ORDER => '非支付订单',
                Code::$INVALIDE_ORDER_NO => '订单不存在',
                Code::$INVALIDE_ORDER_WAIT => '未支付订单',
                Code::$INVALIDE_ORDER_CANCEL => '已取消订单',
                // ##核销
                Code::$TICKET_NOT_EXIST => '报名码不存在',
                Code::$TICKET_NOT_BIND_MAX => '证件重复绑定',
                Code::$TICKET_NOT_MORE_USE => '物资已领取',
                Code::$EXCHANGER_ID_ERROR => '核销密码错误',
                Code::$EXCHANGER_ID_NO_BIND => '未激活',
                Code::$EXCHANGER_ROUTE_ERROR => '路线不一致',
                Code::$TICKET_USED_NOT_BIND => '报名码未绑定',
                Code::$EXCHANGER_STAFF_BIND => '不能重复绑定',
                Code::$EXCHANGER_BIND_OTHER => '密码已使用',
                // ##顾客
                Code::$ERROR_CUSTOMER_NO => '无顾客信息',

                // ##路线
                Code::$EORROR_ROUTE_NO_EXIST => '路线不存在',

                Code:: $API_PARAMS_NULL => '参数不存在',

                Code:: $DB_ERROR => '数据库错误',
                Code:: $DB_SUCCESS => '数据库操作成功',
                Code:: $DB_EXISTED => '数据库已存在',

                Code::$ALREADY_SIGN => '已签到',
                Code::$SUCCESS_CUSTOMER_SIGN => '成功签到',
                Code::$ERROR_CUSTOMER_SIGN => '签到失败',
                Code::$NO_SIGN => '还未签到',
                Code::$NO_MEDAL => '该景点不存在',
                Code::$ALREADY_AWARD => '已领取奖品',
                Code::$NO_GET_AWARD => '未中奖',
                Code::$SUCCESS_GET_AWARD => '恭喜中奖了',
                Code::$NO_MEDAL_STATE => '其他线路红包点不存在',
                Code::$NO_HAVE_MEDAL_STATE => '签到点不存在',
                Code::$HAVING_BIND_INFO =>'已绑定徒步者',
                Code::$NO_BIND_INFO =>'未绑定徒步者',
                Code::$TICKET_BIND  =>'报名码已使用',
                Code::$ERROR_BIND_INFO =>'绑定信息填写有误',

                Code::$ERROR_BIND_Ticket=>'报名码未绑定',
                Code::$ERROR_NO_Open =>'该领奖点未开始',
                Code::$ERROR_STATION_Over=>'该领奖点已结束',
                Code::$ERROR_PASSWORD =>'密码不正确',

                Code::$CUSTOMER_SAVE_ERROR => '用户信息修改失败',
                Code::$CUSTOMER_SAVE_SUCCESS => '用户信息修改成功',
                Code::$CUSTOMER_NOT_EXIST => '用户信息不存在',
                Code::$CUSTOMER_PARAMS_ERROR => '用户参数缺失',
                Code::$CUSTOMER_NOT_MODIFY => '已绑定禁止修改',

                Code::$WX_AUTH_SESSION => '微信授权session_key获取失败',
                Code::$WX_USERINFO_ERROR => '微信授权信息获取失败',
                Code::$WX_AUTH_PARAMS => '微信授权参数缺失',
                Code::$WX_AUTH_SUCCESS => '微信授权成功',
                Code::$WX_TEMPLATEMESS_SUCCESS => '微信模板信息发送成功',
                Code::$WX_TEMPLATEMESS_ERROR => '微信模板信息发送失败',
                Code::$WX_QRCODE_ERROR => '微信二维码创建失败',
                Code::$WX_QRCODE_SUCCESS => '微信二维码创建成功',
                Code::$WX_PATH_ERROR => '微信二维码路径缺失',
                Code::$WX_DECRY_ERROR => '微信解密失败',

                Code::$ADMIN_LOGIN_ERROR => '用户登录信息错误',
                Code::$ADMIN_LOGIN_SUCCESS => '用户登录成功',
                Code::$STAFF_INFO_ERROR => '员工信息错误',

                Code::$VERIFY_CODE_SUCCESS => '验证通过',
                Code::$NEED_SEND_CODE_ERROR => '请先获取验证码',
                Code::$VERIFY_CODE_ERROR => '验证码错误',
                Code::$IS_LOCK => '加锁失败,已有程序在执行',
                Code::$SALLOUT => '已满员，请选择其他线路。',
                Code::$SALLOUT_2 => '已满员，请选择普通版。',
                Code::$ERROR_NO_START => '活动尚未开始'
            ];
        }

        public function getMessage($code) {
            $code = $code ?? Code::$ERROR;
            return new BaseMessage($code, $this->localString[$code] ?? $code);
        }

        public function getSuccess($code) {
            $code = $code ? $code : Code::$SUCCESS;
            return new BaseMessage($code, $this->localString[$code]);
        }

        static public function getInstance() {
            if (!self::$instance) {
                self::$instance = new self();
            }
            return self::$instance;
        }
    }